<template>
  <div id="components-table-demo-size">
    <a-card class="card" :bordered="false">
      <div class="table-operator">
        <a-button type="primary" icon="plus" @click="toAdd()">增加</a-button>
      </div>
      <div class="table">
        <a-table :columns="columns" :dataSource="data" size="middle" :loading="loading" rowKey="id">
          <span slot="action" slot-scope="text,record">
            <template>
              <a @click="toEdit(record.number)">编辑</a>
              <a-divider type="vertical" />
              <a @click="del(record.number)">删除</a>
              <a-divider type="vertical" />
              <a @click="toShow(record.number)">查看</a>
            </template>
          </span>
        </a-table>
      </div>
    </a-card>
  </div>
</template>
<script>
import { getWard, deleteWard } from '../../api/ward'
import { departmentFilter } from '../../dictionary'
const columns = [{
  title: '病房号',
  dataIndex: 'number',
  align: 'center',
  scopedSlots: { customRender: 'number' }
}, {
  title: '床位数',
  dataIndex: 'count',
  align: 'center',
  scopedSlots: { customRender: 'count' }
}, {
  title: '科室',
  dataIndex: 'department',
  align: 'center',
  scopedSlots: { customRender: 'department' },
  customRender: departmentFilter
}, {
  title: '护士',
  dataIndex: 'nurse',
  align: 'center',
  scopedSlots: { customRender: 'nurse' }
}, {
  title: '操作',
  dataIndex: 'action',
  align: 'center',
  scopedSlots: { customRender: 'action' }
}]
const data = []

export default {
  name: 'WardIndex',
  data () {
    return {
      data,
      columns,
      user: this.$store.getters.userInfo,
      loading: true
    }
  },
  methods: {
    toAdd () {
      this.$router.push('/ward/add')
    },
    toEdit (number) {
      this.$router.push('/ward/edit?ward=' + number)
    },
    toShow (number) {
      console.log('ward', number)
      this.$router.push('/ward/show?ward=' + number)
    },
    del (number) {
      const _this = this
      this.$confirm({
        title: '警告',
        content: `真的要删除 ${number} 吗?`,
        okText: '删除',
        okType: 'danger',
        cancelText: '取消',
        onOk () {
          deleteWard(number).then(res => {
            console.log('delete:', number)
            _this.$router.go(0)
          }).catch(res => {})
        },
        onCancel () {}
      })
    }
  },
  filters: {
    departmentFilter
  },
  created () {
    getWard(null, this.user.department).then(res => {
      console.log('res', res)
      this.data = res.result
      this.loading = false
    }).catch(res => {
      this.loading = false
      console.log('res', res)
    })
  }
}
</script>
<style scoped>

</style>
